package facade;

import model.Address;
import model.Contact;
import model.Customer;
import model.Employee;
import model.Enterprise;
import model.EnterprisePersonRelation;
import model.SubjectAttribute;
import db.ImbiConnection;

public class EnterpriseFacade {
	public static void deleteEnterprise(Enterprise e){
		for(Employee employee: e.getEmployees()){
			EmployeeFacade.deleteEmployee(employee);
		}
		for(EnterprisePersonRelation rel: e.getRelatedPersons()){
			ImbiConnection.getEnterprisePersonRelationDAO().delete(rel);
		}
		for(SubjectAttribute attr: e.getAttributes()){
			ImbiConnection.getSubjectAttributeDAO().delete(attr);
		}
		for(Address a: e.getAddressList()){
			ImbiConnection.getAddressDAO().delete(a);
		}
		for(Contact c: e.getContactList()){
			ImbiConnection.getContactDAO().delete(c);
		}
		for(Customer c: ImbiConnection.getCustomerDAO().findByEnterpriseId(e)){
			ImbiConnection.getCustomerDAO().delete(c);
		}		
		ImbiConnection.getEnterpriseDAO().delete(e);
	}
}
